package cn.com.cis.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.cis.domain.Role;
import cn.com.cis.persistence.RoleMapper;
import cn.com.cis.plugins.mybatis.PageHelper;

@Service
@Transactional
public class RoleService {

    @Autowired
    private RoleMapper mapper;

    @Transactional(readOnly = true)
    public List<String> selectPermissionsForRole(int roleId) {
        return mapper.selectPermissionsForRole(roleId);
    }

	public Role selectRoleByRoleId(int roleId) {
		return mapper.selectRoleByRoleId(roleId);
	}

	public List<Role> selectRolesByUserId(int userId) {
		return mapper.selectRolesByUserId(userId);
	}

	public void addPermissionForRole(Integer roleId, String code) {
		mapper.addPermissionForRole(roleId, code);
	}

	public void deletePermissionFromRole(Integer roleId, String code) {
		mapper.deletePermissionFromRole(roleId, code);
	}

	public List<Role> selectRoles(int page, int pageSize) {
		PageHelper.startPage(page, pageSize);
		return mapper.selectRoles();
	}

	public void updateRole(Role role) {
		mapper.updateRole(role);
	}

	public void clearPermissions(int roleId) {
		mapper.clearPermissions(roleId);
	}

	public List<Role> selectRoles() {
		return mapper.selectRoles();
	}

	public void deleteRoleById(int id) {
		mapper.deleteRoleById(id);
	}

	public void insertRole(Role role) {
		mapper.insertRole(role);
	}

	public Role selectRoleByRoleName(String roleName) {
		return mapper.selectRoleByName(roleName);
	}

}
